<?php
class Login_Attempts_Model extends Model 
{
	function Login_Attempts_Model()
	{
		parent::Model();
		
		$this->load->config('redux_auth');
		$this->_tables  = $this->config->item('tables');
	}

	function check_attempts($ip_address)
	{
		$this->db->select('1', FALSE);
		$this->db->where('ip_address', $ip_address);
		return $this->db->get($this->_tables['logins_attempts']);
	}
	
	// Increase attempts count
	function increase_attempt($ip_address)
	{
		// Insert new record
		$data = array(
			'ip_address' => $ip_address
		);

		$this->db->insert($this->_tables['logins_attempts'], $data); 
	}
	
	function clear_attempts($ip_address)
	{		
		$this->db->where('ip_address', $ip_address);
		$this->db->delete($this->_tables['logins_attempts']);
	}	
	
}
?>